package com.xiaoming.api;

import com.xiaoming.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping(value = "/index")
    public String indexView(@RequestParam(required = false,defaultValue = "1") Integer pageNo,
                            @RequestParam(required = false,defaultValue = "3") Integer pageSize,Model model) {
        model.addAttribute("data",articleService.findAll(pageNo, pageSize));
        return "index";
    }

    @GetMapping(value = "/")
    public String homeView(@RequestParam(required = false,defaultValue = "1") Integer pageNo,
                            @RequestParam(required = false,defaultValue = "3") Integer pageSize,Model model) {
        model.addAttribute("data",articleService.findAll(pageNo, pageSize));
        return "index";
    }
}
